package com.deer.wms.base.system.web.bill;

import com.deer.wms.base.system.model.bill.*;
import com.deer.wms.base.system.model.bill.BillInSapCriteria;
import com.deer.wms.base.system.model.bill.BillInSapDetail;
import com.deer.wms.base.system.model.bill.BillInSapDetailCriteria;
import com.deer.wms.base.system.model.bill.BillInSapDto;
import com.deer.wms.base.system.service.bill.BillInSapDetailService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李帅辰
 * @date 2021/6/21 22:37
 */
@Controller
@RequestMapping("/in/billInSapDetail")
public class BillInSapDetailController extends BaseController {

    private String prefix = "in/billInSapDetail";

    @Autowired
    private BillInSapDetailService billInSapDetailService;

//    /*明细列表*/
//    @PostMapping("/findBillInSapDetailList")
//    @ResponseBody
//    public TableDataInfo findList(BillInSapDetailCriteria billInSapDetailCriteria) {
//        startPage();
//        List<BillInSapDetail> billInSapDetailList = billInSapDetailService.findBillInSapDetailList(billInSapDetailCriteria);
//        return getDataTable(billInSapDetailList);
//    }



    /**
     * 导出列表
     */
    @RequiresPermissions("in:billInSapDetail:partExcel")
    @PostMapping("/partExcel")
    @ResponseBody
    public AjaxResult partExcel(@RequestParam  String ids) {
        List<BillInSapDetail> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            BillInSapDetailCriteria b=new BillInSapDetailCriteria();
            b.setBillInSapDetailId(Integer.parseInt(s));
            List<BillInSapDetail> billInSapDetailList = billInSapDetailService.findBillInSapDetailList(b);
            for (BillInSapDetail bs:billInSapDetailList
            ) {
                byIds.add(bs);
            }




    }
        // List<BillInSapDto> billInSapList = billInSapService.findBillInSapDtoList(billInSapCriteria);
        ExcelUtil<BillInSapDetail> util = new ExcelUtil<BillInSapDetail>(BillInSapDetail.class);
        return util.exportExcel(byIds, "收货明细");
    }

    //打印
    @RequestMapping("print")
    public String print(@RequestParam String ids, Model model) {
        List<BillInSapDetail> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            BillInSapDetailCriteria b=new BillInSapDetailCriteria();
            b.setBillInSapDetailId(Integer.parseInt(s));
            List<BillInSapDetail> billInSapDetailList = billInSapDetailService.findBillInSapDetailList(b);
            for (BillInSapDetail bs:billInSapDetailList
            ) {
                byIds.add(bs);
            }


        }

        //System.out.println(ids);

        model.addAttribute("byids", byIds);


        return  "in/billInSap/printsd";
    }




    /**
     * 导出列表
     */
    @RequiresPermissions("in:billInSapDetail:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BillInSapDetailCriteria billInSapDetailCriteria) {
        List<BillInSapDetail> billInSapDetailList = billInSapDetailService.findBillInSapDetailList(billInSapDetailCriteria);
        ExcelUtil<BillInSapDetail> util = new ExcelUtil<BillInSapDetail>(BillInSapDetail.class);
        return util.exportExcel(billInSapDetailList, "收货明细");
    }

}
